<? 
	$title="User List"; 
	$pageid="4";
	$accessid=",a10,";

	if(isset($_POST['btnsubmit']))
	{
		require("required/dbconnect.php");
		
		$voucher_code=mysql_real_escape_string($_POST['voucher_code']);
		$current_voucher_code=mysql_real_escape_string($_POST['current_voucher_code']);
		$voucher_name=mysql_real_escape_string($_POST['voucher_name']);
		$minimum_purhcase=mysql_real_escape_string($_POST['minimum_purchase']);
		$discount_amount=mysql_real_escape_string($_POST['discount_amount']);
		$discount_type=mysql_real_escape_string($_POST['discount_type']);
		$minimum_purchase=mysql_real_escape_string($_POST['minimum_purchase']);
		$times_to_use=mysql_real_escape_string($_POST['times_to_use']);
		$email_subject=mysql_real_escape_string($_POST['email_subject']);
		$email_content=mysql_real_escape_string($_POST['email_content']);
		$send_from_day=mysql_real_escape_string($_POST['send_from_day']);
		$expiry_day=mysql_real_escape_string($_POST['expiry_day']);
		$status=mysql_real_escape_string($_POST['status']);
		$start_date=mysql_real_escape_string($_POST['start_date']);
		$end_date=mysql_real_escape_string($_POST['end_date']);
		$birthday_year=mysql_real_escape_string($_POST['birthday_year']);
		
		
		$chk=mysql_query("select count(*) as result from os_discount_voucher where voucher_code='$voucher_code'");
			
		if(mysql_result($chk,0,"result")>0)
		{

			require("required/dbconnect.php"); 
			require("required/function.php");
			require("required/header.php");
			
			checkAccess("allow_gift_management",1);
?>
<table width="100%"  cellpadding="0" cellspacing="5" height="300">
<tr>


	<td valign="top">
			
            
			<form action="bv_add2.php" method="post">
            <script type="text/javascript" src="required/js/calendarDateInput.js"></script>
			<table width="100%">
			
				<tr>
					<td colspan="3" class="title">
					<strong>Add Birthday Voucher</strong>					
					</td>
				</tr>
               <Tr>
               		<td colspan="3">
                   
                    <div id="dw_failed">Voucher code already exist, please try again.</div>
                    </td>
               </Tr>
               <tr>               
                <td> 
                 <input type="button" value="Back" class="button" name="btnsubmit" onclick="history.go(-1)">
				</td>
			</table>
			</form>
		</td>
	</tr>
	
	
</table>
<? 
			require("required/footer.php");
		}
		else
		{
		
			$update=mysql_query("insert into os_discount_voucher (voucher_code,voucher_name,minimum_purchase,discount_amount,discount_type,times_to_use,email_subject,email_content,send_from_day,expiry_day,status,start_date,end_date,birthday_year,is_birthday_voucher)
			values('$voucher_code','$voucher_name','$minimum_purchase','$discount_amount','$discount_type','$times_to_use','$email_subject','$email_content','$send_from_day','$expiry_day','$status','$start_date','$end_date','$birthday_year',1)")or die(mysql_error());
			
			header("Location:bv_management.php?id=$id&action=1");
		}
	
	}
?>